﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mighty.Common;

namespace Mighty.Brain
{
    public class DreamBrain : BasicBrain
    {
        /// <summary>
        /// 베팅차례
        ///  * 지금까지 배팅된 정보(gameInfo.bettingHistory) 또는 마지막 pass가 아닌 베팅정보 gameInfo.betting를 참고하여 베팅을 결정한다
        /// </summary>
        /// <remarks>
        /// [기본행동] 베팅리밋(betting.limit)이 15이하 이면 베팅리밋을 +1하고 노기루다(Giruda.NoGiruda)로 베팅한다
        /// </remarks>
        public override Betting BettingTicEvent()
        {
            Betting betting = new Betting();
            Betting previousBetting = gameInfo.betting;

            int[] cnt = new int[5];
            for (int i = 0; i < 10; i++)
            {
                HandedCard h = gameInfo.myCards[i];
                cnt[(int)h.shape]++;
                //카드별 무늬에 따른 카드의 갯수가 정해짐
            }

            // cnt[0] cl
            // 1 dia
            // 2

            int max = 0;
            int max_i = 0;
            for (int j = 0; j < 5; j++)
            {
                if (cnt[j] > max)
                {
                    max = cnt[j];
                    max_i = j;
                }
            }


            if (gameInfo.betting.limit < 15)
            {

                switch (max_i)
                {
                    case (int)Shape.Clover:
                        betting.isPass = false;
                        betting.giruda = Giruda.Clover;
                        betting.limit = previousBetting.limit + 1;
                        break;
                    case (int)Shape.Diamond:
                        betting.isPass = false;
                        betting.giruda = Giruda.Diamond;
                        betting.limit = previousBetting.limit + 1;
                        break;
                    case (int)Shape.Heart:
                        betting.isPass = false;
                        betting.giruda = Giruda.Heart;
                        betting.limit = previousBetting.limit + 1;
                        break;
                    case (int)Shape.Spade:
                        betting.isPass = false;
                        betting.giruda = Giruda.Spade;
                        betting.limit = previousBetting.limit + 1;
                        break;
                    default:
                        betting.isPass = true;
                        betting.limit = 13;
                        break;

                }
            }

            else
                betting.isPass = true;


            return betting;
        }
            /*
            Shape.Joker == 6;
            for(int i=10;i<15 ;i++)
            {
               betting.giruda[i]=5;
            }
            for(int i=1;i<10;i++)
            {
                betting.giruda[i]=4;
            }


                   
              
            else
            {
                va
            }
                
                
            //joker은 6, giruda ajqk는 5, giruda 나머지는 4, a는 3, jkq는 2, 나머지는 1

            if(va
        } 
            */



            //betting.isPass = true;
            //if (gameInfo.betting.limit > 0)
            //{
            //    Betting previousBetting = gameInfo.betting;
            //    if (previousBetting.limit < 15)
            //    {
            //        betting.isPass = false;
            //        betting.giruda = Giruda.NoGiruda;
            //        betting.limit = previousBetting.limit + 1;
            //    }
            //}
            //else
            //{
            //    betting.isPass = false;
            //    betting.giruda = Giruda.NoGiruda;
            //    betting.limit = 13;
            //}

            //int[] spadecnt = new spadecnt[13];
            //int[] diamondcnt = new diamondcnt[13];
            //int[] clovercnt = new clovercnt[13];
            //int[] heartcnt = new heartcnt[13];

        public override HandedCard[] ChoiceCardEvent()
        {
            for (int i = 0; i <= 9; i++)
            {
                gameInfo.myCards[i].cmdRemove = false;
            }
            for (int i = 10; i <= 12; i++)
            {
                gameInfo.myCards[i].cmdRemove = true;
            }
            return gameInfo.myCards;
        }


        public override FriendPlayer ChoiceFriendEvent()
        {
            FriendPlayer friend = new FriendPlayer();

            bool mightycard = true;

            if (mightycard)
            {
                friend.howToSelect = FriendPlayer.HowToSelect.card;
                friend.cardCondition = new Card(gameInfo.mighty.shape, gameInfo.mighty.number);
                return friend;
                //friend.cardCondition.shape = Shape.Joker;
            }
            else
            {
                friend.howToSelect = FriendPlayer.HowToSelect.card;
                friend.cardCondition = new Card(Shape.Joker,0);
                return friend;
            }


            return gameInfo.friend;
        }

        
    }
}
